import { smartTranslate as $t, transPlaceholder as $p } from '@/lang';
import { hasAuth } from '@/plugins/permission';


export const getFieldColumns = (options) => {
  return [
    {
      field: 'id',
      title: $t('common.field.id', '编号'),
      width: null,
      align: 'left',
      showOverflow: 'tooltip',
      visible: false,
    },
    {
      field: 'username',
      title: $t('menu.admin.log.field.username', '用户名'),
      width: 'auto',
      align: 'left',
      showOverflow: 'tooltip',
      visible: true,
    },
    {
      field: 'url',
      title: $t('menu.admin.log.field.url', '请求地址'),
      width: 'auto',
      align: 'left',
      showOverflow: 'tooltip',
      visible: true,
    },
    {
      field: 'content',
      title: $t('menu.admin.log.field.content', '请求内容'),
      width: null,
      align: 'left',
      showOverflow: 'tooltip',
      visible: true,
    },
    {
      field: 'ip',
      title: $t('menu.admin.log.field.ip', '客户端地址'),
      width: 'auto',
      align: 'left',
      showOverflow: 'tooltip',
      visible: true,
    },
    {
      field: 'agent',
      title: $t('menu.admin.log.field.agent', '浏览器'),
      width: 'auto',
      align: 'left',
      showOverflow: 'tooltip',
      visible: true,
    },
    {
      field: 'os',
      title: $t('menu.admin.log.field.os', '操作系统'),
      width: 'auto',
      align: 'left',
      showOverflow: 'tooltip',
      visible: true,
    },
    {
      field: 'app',
      title: $t('menu.admin.log.field.app', '应用'),
      width: 'auto',
      align: 'left',
      showOverflow: 'tooltip',
      visible: true,
    },
    {
      field: 'type',
      title: $t('menu.admin.log.field.type', '类型'),
      width: 'auto',
      align: 'left',
      visible: true,
      cellRender: {
        name: 'RaElSelectRender',
        options: options.value['type'],
        props: {
          multiple: false,
        },
      },
    },
    {
      field: 'sort',
      title: $t('common.field.sort', '排序'),
      width: 'auto',
      align: 'left',
      showOverflow: 'tooltip',
      visible: true,
    },
    {
      field: 'status',
      title: $t('common.field.status', '状态'),
      width: 'auto',
      align: 'left',
      visible: true,
      cellRender: {
        name: 'RaDictSelectRender',
        props: {
          type: 'switch',
          code: 'status_options',
          multiple: false,
        },
      },
    },
    {
      field: 'create_id',
      title: $t('common.field.create_id', '创建者'),
      width: null,
      align: 'left',
      showOverflow: 'tooltip',
      visible: false,
    },
    {
      field: 'create_time',
      title: $t('common.field.create_time', '创建时间'),
      width: 'auto',
      align: 'left',
      visible: true,
      cellRender: {
        name: 'ElDatePicker',
        props: {
          type: 'datetime',
          format: 'YYYY-MM-DD HH:mm:ss',
        },
      },
    },
    {
      field: 'update_time',
      title: $t('common.field.update_time', '更新时间'),
      width: 160,
      align: 'left',
      visible: false,
      cellRender: {
        name: 'ElDatePicker',
        props: {
          type: 'datetime',
          format: 'YYYY-MM-DD HH:mm:ss',
        },
      },
    },


    // 结束
  ];
};

export const getActionButtons = ({ actions }) => [
  {
    content: $t('common.action.detail', '详情'),
    type: 'info',
    icon: 'View',
    link: true,
    visible: hasAuth('admin:log:detail'),
    code: 'detail_handle',
    onClick: (row) => actions.dispatchAction('detail_handle', row),
  },


  // 结束
];

export const getFormData = (options) => ({
  keyword: null,
  type: null,
  create_time: null,
});

export const getFormItems = (options) => [
  {
    field: 'keyword',
    title: '关键字',
    folding: true,
    resetValue: null,
    itemRender: {
      name: 'ElInput',
      props: {
        clearable: true,
      },
    },
  },
  {
    field: 'type',
    title: $t('menu.admin.log.field.type', '类型'),
    folding: true,
    resetValue: null,
    itemRender: {
      name: 'ElSelect',
      options: options.value['type'],
      props: {
          placeholder: $t('common.message.placeholder.general', '请输入{field}',{field: $t('menu.admin.log.field.type', '类型')}),
          clearable: true,
      },
    },
  },
  {
    field: 'create_time',
    title: $t('common.field.create_time', '创建时间'),
    folding: true,
    resetValue: null,
    itemRender: {
      name: 'ElDatePicker',
      props: {
        type: 'daterange',
        clearable: true,
      },
    },
  },


  // 结束
];
